<?php
include("../connect/connect.php");

if($_POST['fname'] !="" && $_POST['lname'] !="" && $_POST['name'] !="" && $_POST['phone'] !="" && $_POST['fax'] !="" && $_POST['email'] !=""){
	$date = date("Y-m-d H:i:s");
	mysql_query("INSERT INTO reservation_detail (reservation_detail_fname,reservation_detail_lname,reservation_detail_name,reservation_detail_phone,reservation_detail_fax,reservation_detail_email,reservation_detail_detail,reservation_detail_payment_information,group_detail_id,discount,discount2,reservation_detail_total,reservation_detail_sale_name,reservation_detail_sale_phone,reservation_detail_time) VALUES ('".$_POST['fname']."','".$_POST['lname']."','".$_POST['name']."','".$_POST['phone']."','".$_POST['fax']."','".$_POST['email']."','".$_POST['remark']."','".$_POST['tResep']."','".$_POST['Group_Detail']."','".$_POST['discount']."','".$_POST['discount2']."','".$_POST['rTotal']."','".$_POST['name_r']."','".$_POST['phone_r']."','$date')");
}

//เลือกข้อมูลมาบันทึกลงข้อมูลการจอง
$iQuery = mysql_query("SELECT max(reservation_detail_id) as reservation_detail_id FROM reservation_detail");
$iRow = mysql_fetch_array($iQuery);
$reservation_detail_id = $iRow['reservation_detail_id'];
	$aQuery = mysql_query("SELECT * FROM roomselect_session");
	while($aRow = mysql_fetch_array($aQuery)){
		mysql_query("INSERT INTO reservation (room_id,reservation_checkin,reservation_detail_id) VALUES ('".$aRow['room_id']."','".$aRow['reservation_checkin']."','".$reservation_detail_id."')");
	}

//กรณีเลือก Group
if($_POST['tReseps']=='group'){
	$gCount = count($_POST['list']);
	$cCount = 0;
		for($i=0;$i<$gCount;$i++){
			if($_POST['list'][$i]!="" && $_POST['amount'][$i]!="" && $_POST['price'][$i]!=""){
				$cCount = $cCount+1;
				mysql_query("INSERT INTO reservation_group (reservation_detail_id,reservation_group_list,reservation_group_amount,reservation_group_price) VALUES ('$reservation_detail_id','".$_POST['list'][$i]."','".$_POST['amount'][$i]."','".$_POST['price'][$i]."')");
			}
		}
}

if($_POST['Abf']!=""){
	$AbfQuery = mysql_query("SELECT more_information_price FROM more_information WHERE more_information_id = '1'");
	$AbfRow = mysql_fetch_array($AbfQuery);
	mysql_query("INSERT INTO reservation_information (reservation_detail_id,more_information_id,more_information_value,more_information_price) VALUE ('".$reservation_detail_id."','1','".$_POST['tAbf']."','".$AbfRow['more_information_price']."')");
}

if($_POST['ExtraAbf']!=""){
	$tExtraAbfQuery = mysql_query("SELECT more_information_price FROM more_information WHERE more_information_id = '2'");
	$tExtraAbfRow = mysql_fetch_array($tExtraAbfQuery);
	mysql_query("INSERT INTO reservation_information (reservation_detail_id,more_information_id,more_information_value,more_information_price) VALUE ('".$reservation_detail_id."','2','".$_POST['tExtraAbf']."','".$tExtraAbfRow['more_information_price']."')");
}
if($_POST['Extra']!=""){
	$tExtraQuery = mysql_query("SELECT more_information_price FROM more_information WHERE more_information_id = '3'");
	$tExtraRow = mysql_fetch_array($tExtraQuery);
	mysql_query("INSERT INTO reservation_information (reservation_detail_id,more_information_id,more_information_value,more_information_price) VALUE ('".$reservation_detail_id."','3','".$_POST['tExtra']."','".$tExtraRow['more_information_price']."')");
}
if($_POST['AbfA']!=""){ 	
	$tAbfAQuery = mysql_query("SELECT more_information_price FROM more_information WHERE more_information_id = '4'");
	$tAbfARow = mysql_fetch_array($tAbfAQuery);
	mysql_query("INSERT INTO reservation_information (reservation_detail_id,more_information_id,more_information_value,more_information_price) VALUE ('".$reservation_detail_id."','4','".$_POST['tAbfA']."','".$tAbfARow['more_information_price']."')");
}
if($_POST['AbfC']!=""){ 	
	$tAbfCQuery = mysql_query("SELECT more_information_price FROM more_information WHERE more_information_id = '5'");
	$tAbfCRow = mysql_fetch_array($tAbfCQuery);
	mysql_query("INSERT INTO reservation_information (reservation_detail_id,more_information_id,more_information_value,more_information_price) VALUE ('".$reservation_detail_id."','5','".$_POST['tAbfC']."','".$tAbfCRow['more_information_price']."')");
}
if($_POST['AddA']!=""){ 	
	$tAddAQuery = mysql_query("SELECT more_information_price FROM more_information WHERE more_information_id = '6'");
	$tAddARow = mysql_fetch_array($tAddAQuery);
	mysql_query("INSERT INTO reservation_information (reservation_detail_id,more_information_id,more_information_value,more_information_price) VALUE ('".$reservation_detail_id."','6','".$_POST['tAddA']."','".$tAddARow['more_information_price']."')");
}
if($_POST['AddC']!=""){ 	
	$tAddCQuery = mysql_query("SELECT more_information_price FROM more_information WHERE more_information_id = '7'");
	$tAddCRow = mysql_fetch_array($tAddCQuery);
	mysql_query("INSERT INTO reservation_information (reservation_detail_id,more_information_id,more_information_value,more_information_price) VALUE ('".$reservation_detail_id."','7','".$_POST['tAddC']."','".$tAddCRow['more_information_price']."')");
}

$sID = mysql_query("SELECT max(reservation_detail_id) as reservation_detail_id FROM reservation_detail");
$sRow = mysql_fetch_array($sID);

echo "<script>window.location='roomselect_print.php?id=".$sRow['reservation_detail_id']."';</script>";
?>
